package com.ruoyi.web.controller.gcgl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DecimalCalculateUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gcgl.domain.GcCustomer;
import com.ruoyi.gcgl.domain.GcProject;
import com.ruoyi.gcgl.domain.GcProjectFlow;
import com.ruoyi.gcgl.domain.GcProjectSqkp;
import com.ruoyi.gcgl.domain.GcProjectXmxq;
import com.ruoyi.gcgl.mapper.GcSendTipMapper;
import com.ruoyi.gcgl.service.IGcCustomerService;
import com.ruoyi.gcgl.service.IGcProjectFlowService;
import com.ruoyi.gcgl.service.IGcProjectService;
import com.ruoyi.gcgl.service.IGcProjectSqkpService;
import com.ruoyi.gcgl.service.IGcProjectXmxqService;
import com.ruoyi.gcgl.service.IGcSendTipService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.controller.tool.AliyunSmsUtils;

/**
 * 申请开票Controller
 * 
 * @author ruoyi
 * @date 2022-12-11
 */
@Controller
@RequestMapping("/gcgl/sqkp")
public class GcProjectSqkpController extends BaseController
{
    private String prefix = "gcgl/sqkp";

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IGcProjectSqkpService gcProjectSqkpService;
    @Autowired
    private IGcProjectService gcProjectService;
    @Autowired
    private IGcCustomerService gcCustomerService;
    @Autowired
    private IGcProjectFlowService gcProjectFlowService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private IGcProjectXmxqService gcProjectXmxqService;
    @Autowired
    private IGcSendTipService gcSendTipService;
    @Autowired
    private GcSendTipMapper gcSendTipMapper;
    
    @RequiresPermissions("gcgl:sqkp:view")
    @GetMapping()
    public String sqkp()
    {
        return prefix + "/sqkp";
    }

    /**
     * 查询申请开票列表
     */
    @RequiresPermissions("gcgl:sqkp:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GcProjectSqkp gcProjectSqkp)
    {
        startPage();
        gcProjectSqkp.setDeleteFlag(1);
        if(getSysUser().isShow43R(getUserId())){
        gcProjectSqkp.setCreateUser(getLoginName());
        }
        List<GcProjectSqkp> list = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
        return getDataTable(list);
    }

    /**
     * 导出申请开票列表
     */
    @RequiresPermissions("gcgl:sqkp:export")
    @Log(title = "申请开票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GcProjectSqkp gcProjectSqkp)
    {
    	gcProjectSqkp.setDeleteFlag(1);
    	if(getSysUser().isShow()){
            gcProjectSqkp.setCreateUser(getLoginName());
            }
        List<GcProjectSqkp> list = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
        ExcelUtil<GcProjectSqkp> util = new ExcelUtil<GcProjectSqkp>(GcProjectSqkp.class);
        return util.exportExcel(list, "申请开票数据");
    }

    /**
     * 新增申请开票
     */
    @GetMapping("/add/{gcProjectid}")
    public String add(ModelMap mmap,@PathVariable("gcProjectid") Long gcProjectid){
    	GcProject gcProject = gcProjectService.selectGcProjectById(gcProjectid);
    	mmap.put("gcProject", gcProject);
    	
    	GcProjectXmxq gcProjectXmxq =new GcProjectXmxq();
    	gcProjectXmxq.setGcProjectid(gcProjectid);
    	gcProjectXmxq.setDeleteFlag(1);
    	List<GcProjectXmxq> obj = gcProjectXmxqService.selectGcProjectXmxqList(gcProjectXmxq);
    	mmap.put("gcProjectXmxq", obj.get(0));
    	
    	mmap.put("sqsj", new Date());
    	
    	GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	gcCustomer.setName(gcProject.getCustomerName());
    	List<GcCustomer> lis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	if(lis!=null && lis.size()>0){
    		mmap.put("shuih", lis.get(0).getCkdw()+"/"+lis.get(0).getNssbh());//单位信息名称/税号
        	mmap.put("kaihuh", lis.get(0).getKhyh()+"/"+lis.get(0).getSkzh());//单位信息开户行/帐号
        	mmap.put("dizhi", lis.get(0).getAddress()+"/"+lis.get(0).getPhone());//单位信息地址/电话
    	}else{
    		mmap.put("shuih", "");//单位信息名称/税号
        	mmap.put("kaihuh", "");//单位信息开户行/帐号
        	mmap.put("dizhi", "");//单位信息地址/电话
    	}
    	
    	double ykfpje=0.0;//已开发票金额
    	String ykfpsj = "";//已开发票时间
    	GcProjectSqkp sqkp = new GcProjectSqkp();
        sqkp.setGcProjectid(gcProjectid);
        sqkp.setDeleteFlag(1);
        List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(sqkp);
        for(GcProjectSqkp sqkp1:sqkplis){
        	sqkp1.setCreateUser(DateUtils.dateTime(sqkp1.getSqsj()));
        	ykfpje=DecimalCalculateUtil.add(ykfpje, Double.valueOf(sqkp1.getItemje().toString()));
        	ykfpsj=DateUtils.dateTime(sqkp1.getSqsj());
        }
        mmap.put("sqkplis", sqkplis);
        
        BigDecimal bigDecimal = new BigDecimal(ykfpje);
        String s = bigDecimal.toPlainString();
        mmap.put("ykfpje", s);
        mmap.put("ykfpsj", ykfpsj);
        return prefix + "/add";
    }

    /**
     * 新增保存申请开票
     */
    @RequiresPermissions("gcgl:sqkp:add")
    @Log(title = "申请开票", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public synchronized AjaxResult addSave(GcProjectSqkp gcProjectSqkp){
    	
    	try {
    		gcProjectSqkp.setXmfzr(getLoginName());
        	gcProjectSqkp.setXmfzrAt(new Date());
        	gcProjectSqkp.setStatus(0);
        	gcProjectSqkp.setDeleteFlag(1);
        	gcProjectSqkp.setCreateAt(new Date());
        	gcProjectSqkp.setCreateUser(getLoginName());
        	gcProjectSqkp.setUpdateAt(new Date());
        	gcProjectSqkp.setUpdateUser(getLoginName());
        	
        	SysUser user = sysUserService.selectUserById(getUserId());
        	gcProjectSqkp.setSqrpr(user.getZjsjName());//2024年12月30日修改，增加分管领导审批
        	
        	gcProjectSqkpService.insertGcProjectSqkp(gcProjectSqkp);
        	
        	GcProjectFlow gcProjectFlow = new GcProjectFlow();
        	gcProjectFlow.setGcProjectid(gcProjectSqkp.getGcProjectid());
        	gcProjectFlow.setSqkpsksp(1);
        	gcProjectFlowService.updateGcProjectFlow(gcProjectFlow);
        	
        	//发送消息通知
//        	gcSendTipService.sendTipXm("sqkp", "申请开票", gcProjectSqkp.getOrderNo(), 
//        			gcProjectSqkp.getCreateUser(), DateUtils.dateTime(gcProjectSqkp.getCreateAt()), 
//        			gcProjectSqkp.getStatus().toString(), null, gcProjectSqkp.getId().toString());
        	
        	try {
        		SysUser user1 = sysUserService.selectUserById(user.getZjsjId());
    			String phonenumber = user1.getPhonenumber();//分管领导
    			AliyunSmsUtils.returnSmsTz(phonenumber);
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return toAjax(1);
		}
    	
        return toAjax(1);
    }

    /**
     * 修改申请开票
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GcProjectSqkp gcProjectSqkp = gcProjectSqkpService.selectGcProjectSqkpById(id);
        mmap.put("gcProjectSqkp", gcProjectSqkp);
        
        GcProjectSqkp sqkp = new GcProjectSqkp();
        sqkp.setGcProjectid(gcProjectSqkp.getGcProjectid());
        sqkp.setDeleteFlag(1);
        List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(sqkp);
        for(GcProjectSqkp sqkp1:sqkplis){
        	sqkp1.setCreateUser(DateUtils.dateTime(sqkp1.getSqsj()));
        }
        
        mmap.put("sqkplis", sqkplis);
        return prefix + "/edit";
    }
    
    /**
     * 修改申请开票
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
        GcProjectSqkp gcProjectSqkp = gcProjectSqkpService.selectGcProjectSqkpById(id);
        
        GcProjectSqkp sqkp = new GcProjectSqkp();
        sqkp.setGcProjectid(gcProjectSqkp.getGcProjectid());
        sqkp.setDeleteFlag(1);
        List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(sqkp);
        
        double heje = 0.0;
        if(sqkplis!=null && sqkplis.size()<7){
        	for(GcProjectSqkp obj:sqkplis){
        		obj.setCreateUser(DateUtils.dateTime(obj.getSqsj()));
        		heje = DecimalCalculateUtil.add(heje, Double.valueOf(obj.getItemje().toString()));
        	}
        }
        mmap.put("sqkplis", sqkplis);
        gcProjectSqkp.setHej(heje);
        mmap.put("gcProjectSqkp", gcProjectSqkp);
        return prefix + "/detail";
    }

    /**
     * 修改保存申请开票
     */
    @Log(title = "申请开票", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GcProjectSqkp gcProjectSqkp)
    {
    	gcProjectSqkp.setStatus(0);
    	gcProjectSqkp.setZjlsp("");
    	gcProjectSqkp.setCwkpr("");
    	gcProjectSqkp.setUpdateAt(new Date());
    	gcProjectSqkp.setUpdateUser(getLoginName());
        return toAjax(gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp));
    }

    /**
     * 删除申请开票
     */
    @RequiresPermissions("gcgl:sqkp:remove")
    @Log(title = "申请开票", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gcProjectSqkpService.deleteGcProjectSqkpByIds(ids));
    }
    
    //----------工程
    /**
     * 申请开票评审
     * @return
     */
    @RequiresPermissions("gcgl:sqkp:gcpsview")
    @GetMapping("/gcps")
    public String sqkpgcps(){
        return prefix + "/sqkpgcps";
    }
    
    /**
     * 查询申请开票评审列表
     */
    @PostMapping("/gcpslist")
    @ResponseBody
    public TableDataInfo sqkpgcpslist(GcProjectSqkp gcProjectSqkp)
    {
        startPage();
        gcProjectSqkp.setDeleteFlag(1);
        gcProjectSqkp.setStatus(0);
        List<GcProjectSqkp> list = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
        return getDataTable(list);
    }
    
    @Log(title = "通过", businessType = BusinessType.UPDATE)
    @PostMapping("/gcyes")
    @ResponseBody
    public AjaxResult gcyes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProjectSqkp gcProjectSqkpObj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i].toString()));
    		if(gcProjectSqkpObj!=null){
    			GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    			gcProjectSqkp.setId(Long.parseLong(id[i]));
    			gcProjectSqkp.setStatus(1);
    			gcProjectSqkp.setSqrpr(getLoginName());
    			gcProjectSqkp.setSqrprAt(new Date());
    			gcProjectSqkp.setSpyj(spyj);
    			gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
    			
    			GcProjectSqkp l_obj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i]));
    			//发送消息通知
//            	gcSendTipService.sendTipXm("sqkp", "申请开票", l_obj.getOrderNo(), 
//            			l_obj.getCreateUser(), DateUtils.dateTime(l_obj.getCreateAt()), 
//            			l_obj.getStatus().toString(), null, l_obj.getId().toString());
    			
    			try {
//            		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(l_obj.getCreateUser());
//            		if(userlis!=null && userlis.size()>0){
//            			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
    				String phonenumber = caiw;
            			AliyunSmsUtils.returnSmsTz(phonenumber);
//            		}
    			} catch (Exception e) {
    				// TODO: handle exception
    				e.printStackTrace();
    			}
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/gcno")
    @ResponseBody
    public AjaxResult gcno(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProjectSqkp gcProjectSqkpObj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i].toString()));
    		if(gcProjectSqkpObj!=null){
    			GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    			gcProjectSqkp.setId(Long.parseLong(id[i]));
    			gcProjectSqkp.setStatus(2);
    			gcProjectSqkp.setSqrpr(getLoginName());
    			gcProjectSqkp.setSqrprAt(new Date());
    			gcProjectSqkp.setSpyj(spyj);
    			gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
            	
            	GcProjectFlow obj = new GcProjectFlow();
            	obj.setGcProjectid(Long.parseLong(id[i]));
                obj.setSqkpsksp(0);
                obj.setUpdateAt(new Date());
                obj.setUpdateUser(getLoginName());
            	gcProjectFlowService.updateGcProjectFlow(obj);
            	
            	GcProjectSqkp l_obj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i]));
    			//发送消息通知
//            	gcSendTipService.sendTipXm("sqkp", "申请开票", l_obj.getOrderNo(), 
//            			l_obj.getCreateUser(), DateUtils.dateTime(l_obj.getCreateAt()), 
//            			l_obj.getStatus().toString(), null, l_obj.getId().toString());
            	
            	try {
            		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(l_obj.getCreateUser());
            		if(userlis!=null && userlis.size()>0){
            			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
            			AliyunSmsUtils.returnSmsTz(phonenumber);
            		}
    			} catch (Exception e) {
    				// TODO: handle exception
    				e.printStackTrace();
    			}
    		}
    	}
    	return toAjax(1);
    }
    
    //总经理
    /**
     * 申请开票评审
     * @return
     */
    @RequiresPermissions("gcgl:sqkp:psview")
    @GetMapping("/ps")
    public String sqkpps(){
        return prefix + "/sqkpps";
    }
    
    /**
     * 查询申请开票评审列表
     */
    @PostMapping("/pslist")
    @ResponseBody
    public TableDataInfo sqkppslist(GcProjectSqkp gcProjectSqkp)
    {
        startPage();
        gcProjectSqkp.setDeleteFlag(1);
        gcProjectSqkp.setStatus(3);
        List<GcProjectSqkp> list = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
        return getDataTable(list);
    }
    
    @Log(title = "通过", businessType = BusinessType.UPDATE)
    @PostMapping("/yes")
    @ResponseBody
    public AjaxResult yes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProjectSqkp gcProjectSqkpObj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i].toString()));
    		if(gcProjectSqkpObj!=null){
    			GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    			gcProjectSqkp.setId(Long.parseLong(id[i]));
    			gcProjectSqkp.setStatus(5);
    			gcProjectSqkp.setZjlsp(getLoginName());
    			gcProjectSqkp.setZjlspAt(new Date());
    			gcProjectSqkp.setSpyj(spyj);
    			gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
    			
    			GcProjectSqkp l_obj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i]));
    			//发送消息通知
//            	gcSendTipService.sendTipXm("sqkp", "申请开票", l_obj.getOrderNo(), 
//            			l_obj.getCreateUser(), DateUtils.dateTime(l_obj.getCreateAt()), 
//            			l_obj.getStatus().toString(), null, l_obj.getId().toString());
    			
    			try {
            		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(l_obj.getCreateUser());
            		if(userlis!=null && userlis.size()>0){
            			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
            			AliyunSmsUtils.returnSmsTz(phonenumber);
            		}
    			} catch (Exception e) {
    				// TODO: handle exception
    				e.printStackTrace();
    			}
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/no")
    @ResponseBody
    public AjaxResult no(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProjectSqkp gcProjectSqkpObj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i].toString()));
    		if(gcProjectSqkpObj!=null){
    			GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    			gcProjectSqkp.setId(Long.parseLong(id[i]));
    			gcProjectSqkp.setStatus(6);
    			gcProjectSqkp.setZjlsp(getLoginName());
    			gcProjectSqkp.setZjlspAt(new Date());
    			gcProjectSqkp.setSpyj(spyj);
    			gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
            	
            	GcProjectFlow obj = new GcProjectFlow();
            	obj.setGcProjectid(Long.parseLong(id[i]));
                obj.setSqkpsksp(0);
                obj.setUpdateAt(new Date());
                obj.setUpdateUser(getLoginName());
            	gcProjectFlowService.updateGcProjectFlow(obj);
            	
            	GcProjectSqkp l_obj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i]));
    			//发送消息通知
//            	gcSendTipService.sendTipXm("sqkp", "申请开票", l_obj.getOrderNo(), 
//            			l_obj.getCreateUser(), DateUtils.dateTime(l_obj.getCreateAt()), 
//            			l_obj.getStatus().toString(), null, l_obj.getId().toString());
            	
            	try {
            		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(l_obj.getCreateUser());
            		if(userlis!=null && userlis.size()>0){
            			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
            			AliyunSmsUtils.returnSmsTz(phonenumber);
            		}
    			} catch (Exception e) {
    				// TODO: handle exception
    				e.printStackTrace();
    			}
    		}
    	}
    	return toAjax(1);
    }
    
    //////会计
    /**
     * 申请开票评审
     * @return
     */
    @RequiresPermissions("gcgl:sqkp:hjpsview")
    @GetMapping("/hjps")
    public String sqkphjps(){
        return prefix + "/sqkphjps";
    }
    
    /**
     * 查询申请开票评审列表
     */
    @PostMapping("/hjpslist")
    @ResponseBody
    public TableDataInfo sqkphjpslist(GcProjectSqkp gcProjectSqkp)
    {
        startPage();
        gcProjectSqkp.setDeleteFlag(1);
        String[] statuslis = new String[]{"1","3","5","7"};
        gcProjectSqkp.setStatuslis(statuslis);
        List<GcProjectSqkp> list = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
        return getDataTable(list);
    }
    
    @Log(title = "通过", businessType = BusinessType.UPDATE)
    @PostMapping("/hjyes")
    @ResponseBody
    public AjaxResult hjyes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProjectSqkp gcProjectSqkpObj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i].toString()));
    		if(gcProjectSqkpObj!=null){
    			GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    			gcProjectSqkp.setId(Long.parseLong(id[i]));
    			gcProjectSqkp.setStatus(3);
    			gcProjectSqkp.setCwkpr(getLoginName());
    			gcProjectSqkp.setCwkprAt(new Date());
    			gcProjectSqkp.setSpyj(spyj);
    			gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
    			
    			GcProjectSqkp l_obj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i]));
    			//发送消息通知
//            	gcSendTipService.sendTipXm("sqkp", "申请开票", l_obj.getOrderNo(), 
//            			l_obj.getCreateUser(), DateUtils.dateTime(l_obj.getCreateAt()), 
//            			l_obj.getStatus().toString(), null, l_obj.getId().toString());
    			
    			try {
//            		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(l_obj.getCreateUser());
//            		if(userlis!=null && userlis.size()>0){
//            			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
    				String phonenumber = zjl;
            			AliyunSmsUtils.returnSmsTz(phonenumber);
//            		}
    			} catch (Exception e) {
    				// TODO: handle exception
    				e.printStackTrace();
    			}
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/hjno")
    @ResponseBody
    public AjaxResult hjno(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProjectSqkp gcProjectSqkpObj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i].toString()));
    		if(gcProjectSqkpObj!=null){
    			GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    			gcProjectSqkp.setId(Long.parseLong(id[i]));
    			gcProjectSqkp.setStatus(4);
    			gcProjectSqkp.setCwkpr(getLoginName());
    			gcProjectSqkp.setCwkprAt(new Date());
    			gcProjectSqkp.setSpyj(spyj);
    			gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
            	
            	GcProjectFlow obj = new GcProjectFlow();
            	obj.setGcProjectid(Long.parseLong(id[i]));
                obj.setSqkpsksp(0);
                obj.setUpdateAt(new Date());
                obj.setUpdateUser(getLoginName());
            	gcProjectFlowService.updateGcProjectFlow(obj);
            	
            	GcProjectSqkp l_obj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i]));
    			//发送消息通知
//            	gcSendTipService.sendTipXm("sqkp", "申请开票", l_obj.getOrderNo(), 
//            			l_obj.getCreateUser(), DateUtils.dateTime(l_obj.getCreateAt()), 
//            			l_obj.getStatus().toString(), null, l_obj.getId().toString());
            	
            	try {
            		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(l_obj.getCreateUser());
            		if(userlis!=null && userlis.size()>0){
            			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
            			AliyunSmsUtils.returnSmsTz(phonenumber);
            		}
    			} catch (Exception e) {
    				// TODO: handle exception
    				e.printStackTrace();
    			}
    		}
    	}
    	return toAjax(1);
    }
    
    /**
     * 增值税发票开具申请单
     */
    @RequiresPermissions("gcgl:sqkp:print")
    @GetMapping("/sqkpprint/{id}")
    public String sqkpprint(@PathVariable("id") Long id, ModelMap mmap){
        GcProjectSqkp gcProjectSqkp = gcProjectSqkpService.selectGcProjectSqkpById(id);
        
        String projectType = dictDataService.selectDictLabel("gcgl_project_type", gcProjectSqkp.getXmlx());
        String fpType = dictDataService.selectDictLabel("gcgl_project_fp", gcProjectSqkp.getFplx());
        mmap.put("projectType", projectType);
        mmap.put("fpType", fpType);
        
        GcProjectSqkp sqkp = new GcProjectSqkp();
        sqkp.setGcProjectid(gcProjectSqkp.getGcProjectid());
        sqkp.setDeleteFlag(1);
        List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(sqkp);
        
        double heje = 0.0;
        if(sqkplis!=null && sqkplis.size()<7){
        	
        	for(GcProjectSqkp obj:sqkplis){
        		heje = DecimalCalculateUtil.add(heje, Double.valueOf(obj.getItemje().toString()));
        	}
        	
        	for(int i=sqkplis.size();i<=7;i++){
        		GcProjectSqkp obj = new GcProjectSqkp();
        		sqkplis.add(obj);
        	}
        }
        mmap.put("sqkplis", sqkplis);
        gcProjectSqkp.setHej(heje);
        mmap.put("gcProjectSqkp", gcProjectSqkp);
        return prefix + "/sqkpprint";
    }
    
    @Log(title = "通过", businessType = BusinessType.UPDATE)
    @PostMapping("/hjconfirm")
    @ResponseBody
    public AjaxResult hjconfirm(String ids, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProjectSqkp gcProjectSqkpObj = gcProjectSqkpService.selectGcProjectSqkpById(Long.parseLong(id[i].toString()));
    		if(gcProjectSqkpObj!=null){
    			GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    			gcProjectSqkp.setId(Long.parseLong(id[i]));
    			gcProjectSqkp.setStatus(7);
    			gcProjectSqkp.setUpdateUser(getLoginName());
    			gcProjectSqkp.setUpdateAt(new Date());
    			gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @GetMapping("/sqkpzjlsp/{id}")
    public String sqkpzjlsp(@PathVariable("id") Long id, ModelMap mmap){
        GcProjectSqkp gcProjectSqkp = gcProjectSqkpService.selectGcProjectSqkpById(id);
        
        String projectType = dictDataService.selectDictLabel("gcgl_project_type", gcProjectSqkp.getXmlx());
        String fpType = dictDataService.selectDictLabel("gcgl_project_fp", gcProjectSqkp.getFplx());
        mmap.put("projectType", projectType);
        mmap.put("fpType", fpType);
        
        GcProjectSqkp sqkp = new GcProjectSqkp();
        sqkp.setGcProjectid(gcProjectSqkp.getGcProjectid());
        sqkp.setDeleteFlag(1);
        List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(sqkp);
        
        double heje = 0.0;
        if(sqkplis!=null && sqkplis.size()<7){
        	
        	for(GcProjectSqkp obj:sqkplis){
        		heje = DecimalCalculateUtil.add(heje, Double.valueOf(obj.getItemje().toString()));
        	}
        	
        	for(int i=sqkplis.size();i<=7;i++){
        		GcProjectSqkp obj = new GcProjectSqkp();
        		sqkplis.add(obj);
        	}
        }
        mmap.put("sqkplis", sqkplis);
        gcProjectSqkp.setHej(heje);
        mmap.put("gcProjectSqkp", gcProjectSqkp);
        return prefix + "/sqkpzjlsp";
    }
    
    @GetMapping("/sqkphjsp/{id}")
    public String sqkphjsp(@PathVariable("id") Long id, ModelMap mmap){
        GcProjectSqkp gcProjectSqkp = gcProjectSqkpService.selectGcProjectSqkpById(id);
        
        String projectType = dictDataService.selectDictLabel("gcgl_project_type", gcProjectSqkp.getXmlx());
        String fpType = dictDataService.selectDictLabel("gcgl_project_fp", gcProjectSqkp.getFplx());
        mmap.put("projectType", projectType);
        mmap.put("fpType", fpType);
        
        GcProjectSqkp sqkp = new GcProjectSqkp();
        sqkp.setGcProjectid(gcProjectSqkp.getGcProjectid());
        sqkp.setDeleteFlag(1);
        List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(sqkp);
        
        double heje = 0.0;
        if(sqkplis!=null && sqkplis.size()<7){
        	
        	for(GcProjectSqkp obj:sqkplis){
        		heje = DecimalCalculateUtil.add(heje, Double.valueOf(obj.getItemje().toString()));
        	}
        	
        	for(int i=sqkplis.size();i<=7;i++){
        		GcProjectSqkp obj = new GcProjectSqkp();
        		sqkplis.add(obj);
        	}
        }
        mmap.put("sqkplis", sqkplis);
        gcProjectSqkp.setHej(heje);
        mmap.put("gcProjectSqkp", gcProjectSqkp);
        return prefix + "/sqkphjsp";
    }
    
    @GetMapping("/sqkpgcsp/{id}")
    public String sqkpgcsp(@PathVariable("id") Long id, ModelMap mmap){
        GcProjectSqkp gcProjectSqkp = gcProjectSqkpService.selectGcProjectSqkpById(id);
        
        String projectType = dictDataService.selectDictLabel("gcgl_project_type", gcProjectSqkp.getXmlx());
        String fpType = dictDataService.selectDictLabel("gcgl_project_fp", gcProjectSqkp.getFplx());
        mmap.put("projectType", projectType);
        mmap.put("fpType", fpType);
        
        GcProjectSqkp sqkp = new GcProjectSqkp();
        sqkp.setGcProjectid(gcProjectSqkp.getGcProjectid());
        sqkp.setDeleteFlag(1);
        List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(sqkp);
        
        double heje = 0.0;
        if(sqkplis!=null && sqkplis.size()<7){
        	
        	for(GcProjectSqkp obj:sqkplis){
        		heje = DecimalCalculateUtil.add(heje, Double.valueOf(obj.getItemje().toString()));
        	}
        	
        	for(int i=sqkplis.size();i<=7;i++){
        		GcProjectSqkp obj = new GcProjectSqkp();
        		sqkplis.add(obj);
        	}
        }
        mmap.put("sqkplis", sqkplis);
        gcProjectSqkp.setHej(heje);
        mmap.put("gcProjectSqkp", gcProjectSqkp);
        return prefix + "/sqkpgcsp";
    }
}